package link;

import array.ListNode;

import java.util.List;

public class OddEvenLinkedList328 {
    public ListNode oddEvenList(ListNode head) {
        ListNode odd = new ListNode();
        ListNode odd_tmp = odd;
        ListNode even = new ListNode();
        ListNode even_tmp = even;
        boolean isOdd =true;
        while (head!=null){
            if (isOdd) {
                odd_tmp.next = head;
                odd_tmp = odd_tmp.next;
            }else {
                even_tmp.next = head;
                even_tmp = even_tmp.next;
            }
            head=head.next;
            isOdd=!isOdd;
        }
        even_tmp.next = null;
        odd_tmp.next=even.next;
        return odd.next;
    }
}
